﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class MerchantManagementDAL
    {
        private static string conn = ConfigurationSettings.AppSettings["con"].ToString();
        /// <summary>
        /// 首页按日期获取充值-消费汇总
        /// </summary>
        /// <param name="openid">openid</param>
        /// <param name="strattime">开始日期</param>
        /// <param name="endtime">结束日期</param>
        /// <returns></returns>
        public static DataSet MerHomeData(string openid,string strattime,string endtime)
        {
            DataSet dataSet = new DataSet();
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@openid",openid),
                new SqlParameter("@strattime",strattime),
                new SqlParameter("@endtime",endtime)
            };
            try
            {
                string sql = "Me_MerchantManagement";
                return SqlHelper.ExecuteDataSet(conn,CommandType.StoredProcedure,sql,sp);
            }
            catch (Exception ex)
            {
                ApplicationLog.Write("merhomeata错误："+ex.Message);
                return dataSet;
            }
        }

        /// <summary>
        /// 获取食堂
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        public static DataTable InfoCanteen(string openid) 
        {
            DataTable dataTable = new DataTable();
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@openid",openid)
            };
            try
            {
                string sql = @"declare @jh nvarchar(max)
                                --获取机号权限
                                --select @jh =visible_jh from qx a with(nolock) inner join ryxx  b with(nolock) on a.userno =b.userno inner join IdBind c with(nolock) on b.ryid =c.ryid where c.openid =@openid
                                select @jh =visible_jh from qx a with(nolock) where username=@openid
                                select distinct wz from jhsz with(nolock) where CHARINDEX(right(REPLICATE('0',10)+CONVERT( varchar(10),jh),3),(@jh)) >= 1  ";
                return SqlHelper.ExecuteDataSet(conn, CommandType.Text, sql, sp).Tables[0];
            }
            catch (Exception ex)
            {
                ApplicationLog.Write("InfoCanteen错误："+ex.Message);
                return dataTable;
            }
        }


        public static DataTable InfoDangkou(string openid)
        {
            DataTable dataTable = new DataTable();
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@openid",openid)
            };
            try
            {
                string sql = @"declare @jh nvarchar(max)
                                        --获取机号权限
                                        --select @jh =visible_jh from qx a with(nolock) inner join ryxx  b with(nolock) on a.userno =b.userno inner join IdBind c with(nolock) on b.ryid =c.ryid where c.openid =@openid
                                        select @jh =visible_jh from qx a with(nolock) where username=@openid
                                        select distinct zm from fzmx  with(nolock) where CHARINDEX(right(REPLICATE('0',10)+CONVERT( varchar(10),jh),3),(@jh)) >= 1  ";
                return SqlHelper.ExecuteDataSet(conn, CommandType.Text, sql, sp).Tables[0];
            }
            catch (Exception ex)
            {
                ApplicationLog.Write("InfoDangkou错误：" + ex.Message);
                return dataTable;
            }
        }
        /// <summary>
        /// 获取食堂汇总
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="strattime"></param>
        /// <param name="endtime"></param>
        /// <returns></returns>

        public static DataSet InfoCandata(string openid,string cantname, string strattime, string endtime) 
        {
            DataSet dataset = new DataSet();
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@openid",openid),
                new SqlParameter("@cantname",cantname),
                new SqlParameter("@strattime",strattime),
                new SqlParameter("@endtime",endtime)
            };
            try
            {
                string sql = "Me_Canteen";
                return SqlHelper.ExecuteDataSet(conn, CommandType.StoredProcedure, sql, sp);
            }
            catch (Exception ex)
            {
                ApplicationLog.Write("Me_Canteen错误：" + ex.Message);
                return dataset;
            }
        }

        /// <summary>
        /// 按档口汇总
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="dangkou"></param>
        /// <param name="strattime"></param>
        /// <param name="endtime"></param>
        /// <returns></returns>
        public static DataSet InfoDangkouData(string openid, string dangkou, string strattime, string endtime)
        {
            DataSet dataset = new DataSet();
            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@openid",openid),
                new SqlParameter("@dangkou",dangkou),
                new SqlParameter("@strattime",strattime),
                new SqlParameter("@endtime",endtime)
            };
            try
            {
                string sql = "Me_Dangkou";
                return SqlHelper.ExecuteDataSet(conn, CommandType.StoredProcedure, sql, sp);
            }
            catch (Exception ex)
            {
                ApplicationLog.Write("InfoDangkouData错误：" + ex.Message);
                return dataset;
            }
        }


    }
}
